home *** CD-ROM | disk | FTP | other *** search
- Path: peacock.tcinc.com!news
- From: Christopher Sweeney <csweeney>
- Newsgroups: comp.lang.c++
- Subject: Re: protected access to grandparent class
- Date: 4 Mar 1996 22:29:52 GMT
- Organization: Tele-Communications, Inc.
- Message-ID: <4hfqt0$2a8@peacock.tcinc.com>
- References: <Dnqstp.Jo9@uns.bris.ac.uk>
- NNTP-Posting-Host: aitsun24.tcinc.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.12 (X11; I; SunOS 5.4 sun4m)
- X-URL: news:Dnqstp.Jo9@uns.bris.ac.uk
-
- nathan@pact.srf.ac.uk (Nathan Sidwell) wrote:
- >The following class heirarchy is giving me grief.
- >-snip
- >class A {
- >protected:
- > int member;
- > void func(A){};
- >};
- >
- >class B : protected A {
- >protected:
- > void func(B arg) {
- > A::func(A(arg)); // ok
- > };
- >};
- >
- >class C : protected B {
- >protected:
- > void func(C arg) {
- > A::func(A(arg)); // failed
- > };
- >};
- >-snip
- >
- >As far as I can determined the line marked 'failed' is class C's equivalent
- >of the line marked 'ok'. However, g++ 2.7.2 says,
- >
- >foo.cc: In method `void C::func(class C)':
- >foo.cc:17: fields of `const A' are inaccessible in `C' due to private inheritance
- >foo.cc:5: in passing argument 1 of `A::A(const A &)'
- >foo.cc:17: in conversion to type `A'
- >
- >and cfront says,
- >
- >"foo.cc", line 17: error: cast: C* -> base A*; protected base class
- >"foo.cc", line 17: error: object or pointer missing for A::func() of type void A::(A)
- >
- >however, SGI CC accepts the code.
- >
- >I can't see anything in 11.2 of the draft standard which indicates that the rule
- >it describes cannot be applied recursively -- it doesn't describe any other
- >method for determining the access to grandparent members.
- >
- >Is my understanding incomplete or are g++ and cfront confused?
- >
- The ARM does not specify behaviour for "protected" base classes, only private
- and public.
- The "Draft Standard" includes use of protected base classes. It appears that
- the versions
- of g++ and cfront you are using are equating protected base class with private
- base class.
-
- From my reading of the draft standard the SGI compiler is correct.
- C.
-
-